/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vetalitet.xml;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.Transformer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 *
 * @author Vetalitet
 */
public class XmlUtil {

    public static void buildTemplate() throws ParserConfigurationException, FileNotFoundException, TransformerConfigurationException, TransformerException {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.newDocument();
        final Element root = document.createElement("root");
        document.appendChild(root);
        // save xml document to file
        final Source xmlSource = new DOMSource(document);
        final Result result = new StreamResult(new FileOutputStream("D:/users.xml"));
        final TransformerFactory transformerFactory = TransformerFactory.newInstance();
        final Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty("indent", "yes");
        transformer.transform(xmlSource, result);
    }
}
